Handle uncaught NumberFormatException at 20 parse sites (CodeQL java/uncaught-number-format-exception)#229
Open
vharseko wants to merge 2 commits into
Conversation
…uncaught-number-format-exception) Each site called Integer/Long/Double parsing on a value that reaches it without a surrounding catch, so malformed input escaped as a raw NumberFormatException. Every site is now routed to the failure mode that already fits its method contract, so callers get a controlled result instead of a leaking runtime exception. Untrusted / client input -> proper error: - MemoryBackend.Cookie.valueOf: an invalid pagedResultsCookie now yields BadRequestException (HTTP 400) instead of a 500; the caller maps it to a failed promise. - ElasticsearchAuditEventHandler.queryEvents: an invalid pagedResultsCookie now returns BadRequestException.asPromise() (400) instead of a 500. - QueryFilterParser: a non-numeric assertion value now returns the parser's existing valueOfIllegalArgument() result instead of throwing. - JwtClaimsSet: a non-numeric "exp" string claim now throws JwtRuntimeException (the class's own type-checking exception) with a clear message. Configuration input -> clear message / documented default: - AbstractJwtSessionModule: the token-idle-time and max-token-life settings are parsed via a helper that throws AuthenticationException naming the bad setting instead of a raw NumberFormatException. - AsynchronousTextWriter: an invalid CAPACITY system property now logs a warning and falls back to the default (32000) instead of failing class init. - RhinoScriptEngine: an invalid recompile-interval config value now logs a warning and falls back to the documented default (-1). - CrestIntegerSchema.setExample: a non-integer example now throws ValidationException (the schema classes' idiom) instead of a raw NFE. Sentinel-returning parsers -> existing sentinel: - Key/KeyParser.unicode(): a malformed \uXXXX escape now returns the method's existing -1 "cannot parse" sentinel. - JournalManager.fileToGeneration(): a non-numeric generation now returns the method's existing -1, matching the no-match branch. - Warning.valueOf(): a non-numeric warn-code now returns null, matching the method's documented "null if it could not be parsed" contract. Internal, developer-controlled specs -> loud but described failure: - ManagementTableModel.setup() and AdminUI.addLabeledField(): a malformed column/component specification now throws IllegalArgumentException naming the offending spec instead of a bare NumberFormatException. Behaviour is unchanged for valid input. Compiles: mvn -o -am compile across all eleven affected modules -> BUILD SUCCESS.
maximthomas
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves all 20
java/uncaught-number-format-exceptionCodeQL alerts (11 modules).Each flagged site parsed an
int/long/doublefrom a value that could reachit malformed, with no surrounding
catch, so bad input escaped as a rawNumberFormatException. Every site is now routed to the failure mode thatalready matches its method contract, so callers get a controlled result rather
than a leaking runtime exception. Behaviour is unchanged for valid input.
Fixes by category
Untrusted / client input → proper error
MemoryBackendpagedResultsCookie→BadRequestException(HTTP 400) instead of 500;Cookie.valueOfnow declaresthrows ResourceExceptionand the caller returnse.asPromise().ElasticsearchAuditEventHandlerpagedResultsCookie→BadRequestException.asPromise()(400) instead of 500.QueryFilterParservalueOfIllegalArgument(tokenizer)result.JwtClaimsSetexpstring claim →JwtRuntimeException(the class's own type-check exception) with a clear message.Configuration input → clear message / documented default
AbstractJwtSessionModuleAuthenticationExceptionnaming the bad setting.AsynchronousTextWriterCAPACITYsystem property → warn + fall back to default32000(no longer fails class init).RhinoScriptEngine-1.CrestIntegerSchemaexample→ValidationException(the Crest schema idiom).Sentinel-returning parsers → existing sentinel
KeyParser.unicode()\uXXXXescape → the method's existing-1"cannot parse" sentinel.JournalManager.fileToGeneration()-1(matches the no-match branch).Warning.valueOf()null, matching the documented "null if it could not be parsed" contract.Internal, developer-controlled specs → loud but described failure
ManagementTableModel.setup()IllegalArgumentExceptionnaming the offending spec.AdminUI.addLabeledField()IllegalArgumentExceptionnaming the value.Notes
Warning.valueOf([0-9]{3}) andJournalManager.fileToGeneration(\d{12})parse regex-guaranteed digit groups that cannot actually overflow today; the
guards route to each method's existing failure return, so they are cheap
hardening against future regex drift rather than dead code.
Testing
mvn -o -am compileacross all eleven affected modules — BUILD SUCCESS.